![]() ![]() ![]() ![]() | Using Layout Managers |
Note: Before you start creating a custom layout manager, make sure that no existing layout manager will work. In particular, GridBagLayoutis flexible enough to work in most cases.
To create a custom layout manager, you must create a class that implements the LayoutManager
interface. Besides implementing the five methods required by LayoutManager, layout managers generally implement at least one public constructor and the toString()
method. Layout managers don't actually draw Components. They simply invoke each Component's resize(), move(), and/or reshape() methods to set the Component's size and position.
Here's an example custom layout manager. It lays out components diagonally, from left to right, with one component per row.
Here's the example, running as an applet:
![]() ![]() ![]() ![]() | Using Layout Managers |